import axios from "axios";
import NprGress from 'nprogress'
import 'nprogress/nprogress.css'
import { Message } from 'antd'
//   开发   线上

// 白名单
const whiteList = [{
    url: "/api/getList",
    method: "get"
}]


let baseUrl = "" 
// development   开发环境
// production    生产环境
// if (process.env.NODE_ENV === "development") {
//     baseUrl = "/aaaaaaa"
// } else {
//     baseUrl = "/bbbbbbb"
// }

axios.defaults.baseURL = baseUrl
axios.defaults.timeout = 30000


axios.interceptors.request.use((config) => {
    // config  关于请求的配置项信息
    NprGress.start()
    const token = localStorage.getItem('token')? localStorage.getItem('token'): 'aaaa'
    config.headers.Authorization = token
    return config
})

axios.interceptors.response.use((data) => {
    NprGress.done()
    const flag = whiteList.some((item) => {
        if (item.method === data.config.method && item.url === data.config.url) {
            Message.success("请求成功")
        }
    })
    return data.data
}, (error) => {
    switch(error.status) {
        case "500":
            Message.error("服务的错误")
            break
    }
})


export default axios